package com.example.chirdrenserver.controller;

import com.example.chirdrenserver.Holder.UserHolder;
import com.example.chirdrenserver.Pojo.dto.PostDTO;
import com.example.chirdrenserver.Pojo.dto.UserUpdateDTO;
import com.example.chirdrenserver.Service.UserService.PostService;
import com.example.chirdrenserver.Service.UserService.UserService;
import com.example.chirdrenserver.Utils.Result;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    PostService postService;

    /**
     * 更新用户
     * @param userUpdateDTO
     * @return
     */
    @PostMapping("/update")
    public Result updateUser(UserUpdateDTO userUpdateDTO) {
        userService.updateUser(userUpdateDTO);
        return Result.success();
    }

    /**
     * 查询所有用户发布所有帖子
     * @return
     */
    @PostMapping("/post")
    public Result postManagement()
    {
        postService.getPostByUserId((Long) UserHolder.get());
        return Result.success();
    }

    /**
     * 发布帖子
     * @param postDTO
     * @return
     */
    @PutMapping
    public Result putPost(@RequestBody PostDTO postDTO) {
        postService.putPost(postDTO);
        return Result.success();
    }

    /**
     * 获取用户详细信息
     * @return
     */
    @PostMapping("/info")
    public Result getInfo() {
        userService.getById((Long)UserHolder.get());
        return Result.success();
    }
}
